<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="formdata.telephone" placeholder="请输入您的用户名" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="formdata.password" placeholder="请输入您的密码" type="password" />
			</uni-forms-item>
			<uni-forms-item label="" name="">				
					<button type="default" @click="login">登录</button>
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<navigator url="../register/register" open-type="navigate">
					<button type="primary">注册</button>
				</navigator>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formdata: {
					telephone: '12345678912',
					password: '123456'
				}
			}
		},
		methods: {
			login() {
				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'POST',
					data: this.formdata,
					success: res => {
						if (res.data.success) {
							uni.clearStorageSync('formdata')
							uni.setStorageSync('formdata', res.data.data)
							console.log(res.data);
							uni.switchTab({
								url: '../my'
							})
							uni.showToast({
								title: '登录成功',
								icon: 'none'
							});
						} else {
							uni.showToast({
								title: '登录失败',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad: () => {
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)

			})
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
